import {fileURLToPath, URL} from 'node:url'

import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'

// ElementUIPlus按需导入
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import {ElementPlusResolver} from 'unplugin-vue-components/resolvers'
import * as fs from 'node:fs'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueJsx(),
    // ...
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver({ importStyle: 'sass' })],
    }),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  server: {
    host: '127.0.0.1',
    port: 5173,
    // https: {
    //   key: fs.readFileSync('./certs/server.key'), // 私钥文件路径
    //   cert: fs.readFileSync('./certs/server.crt') // 证书文件路径
    // },
    proxy: {
      '/api': {
        // target: "https://localhost:8080",
        target: "http://localhost:8080",
        changeOrigin: true,
        // secure: false, // 如果是自签名证书，可以设置此选项为false来忽略SSL验证
        rewrite: path => path.replace(/^\/api/, ""),
      }
    }
  }
})
